/*
 * test.cpp
 *
 *  Created on: Sep 14, 2012
 *      Author: xx255000
 */

#include "../includes/test.h"

void TestLinkedList() {
	int a[] = {1, 2, 3, 4, 5};
	LinkListNode* h = NULL;
	h = CreateLinkedList(a, 0, 5, h);
	PrintLinkedList(h);
	h = ReverseLinkedList(h);
	PrintLinkedList(h);
	h = ReverseLinkedListRecursively(h);
	PrintLinkedList(h);
	PrintBackwardsKthNode(h, 2);

	DestroyLinkedList(h);

	h = NULL;
	h = CreateLinkedList(a, 0, 5, h);
	int b[] = {7, 8, 9, 10};
	LinkListNode* l = NULL;
	l = CreateLinkedList(b, 0, 4, l);
	cout<<TwoLinkedListCrosses(h, l)<<endl;

	DestroyLinkedList(h);
	DestroyLinkedList(l);
}

void TestTree() {
//	int a[] = {10, 6, 14, 4, 8, 12, 16};
	TreeNode* t = NULL;
//	t = CreateTree(a, 0, 7, t);
//	RecursivelyPreVisitTree(t);
//	cout<<endl;
//	RecursivelyMidVisitTree(t);
//	cout<<endl;
//	RecursivelyPostVisitTree(t);
//	cout<<endl;
//	VisitTreeByLevel(t);
//	cout<<endl;
//	DestroyTree(t);
//
	int b[] = {10, -5, 12, 4, 7, 3, 2, 0, 6};
//	t = NULL;
//	t = CreateTree(b, 0, 9, t);
//	PrintPathEqualsN(t, 25);
//	cout<<endl;
//	DestroyTree(t);
//
//	int c[] = {10, 6, 14, 4, 8, 12, 16};
//	t = NULL;
//	t = CreateTree(c, 0, 7, t);
//	DBListNode* l = NULL;
//	ConvertToDBList(t, l);
//	PrintDBList(l);
//	DeleteDBList(l);
//
//	int d[] = {8, 6, 10, 5, 7, 9, 11};
//	t = NULL;
//	t = CreateTree(d, 0, 7, t);
//	VisitTreeByLevel(t);
//	cout<<endl;
//	t = RecursivelySwitchTree(t);
//	VisitTreeByLevel(t);
//	cout<<endl;
//	SwitchTree(t);
//	VisitTreeByLevel(t);
//	cout<<endl;
//	DestroyTree(t);
//
//	t = NULL;
//	t = CreateTree(d, 0, 7, t);
//	VisitTreeByLevel(t);
//	cout<<endl;
//	TreeNode* n = GetNearestCommonParent(t, t->left->left, t->left->right);
//	cout<<t->left->left->value<<"\t"<<t->left->right->value<<":\t"<<n->value<<endl;
//	DestroyTree(t);

	t = NULL;
	t = CreateTree(b, 0, 9, t);
	cout<<GetMaxSubTreeSum(t)<<endl;
	DestroyTree(t);
}

void TestUtil() {
	int a[] = {1, -2, 3, 10, -4, 7, 2, -5};
//	cout<<IsPostVisitSeqOfBSTree(a, 0, 8)<<endl;
	cout<<GetMaxContinuousSum(a, 0, 8)<<endl;
//	int b[] = {1, 2, 4, 7, 11, 15};
//	cout<<ExistSumEqualsN(b, 0, 6, 15)<<endl;
//	int c[] = {9, 4, 3, 2, 5, 4, 3, 2};
//	cout<<GetMaxContinuousSubSequence(c, 0, 8)<<endl;
//	cout<<"b:"<<IsAscendingSequenceRecursively(b, 0, 6)<<endl;
//	cout<<"c:"<<IsAscendingSequenceRecursively(c, 0, 8)<<endl;
//	PrintContinueSumEqualsN(30);
//	PrintValues(b, 0, 6);
//	LeftOddRightEven(b, 0, 6);
//	PrintValues(b, 0, 6);
//	int d[] = {5, 7, 6, 9, 11, 10, 8};
//	int e[] = {7, 4, 6, 5};
//	cout<<IsPostVisitSeqOfBSTree(d, 0, 7)<<"\t";
//	cout<<IsPostVisitSeqOfBSTree(e, 0, 4)<<endl;
//
//	int f[] = {1, 2, 5, 2, 9, 3, 7, 5, 1, 3, 8, 7};
//	int num1 = 0, num2 = 0;
//	FindTwoNumsAppearsOnce(f, 0, 12, num1, num2);
//	cout<<num1<<"\t"<<num2<<endl;
//
//	cout<<FindNthUglyNum(7)<<endl;
//
//	int g[] = {176, 178, 180, 170, 171};
//	cout<<GetTroubleMakerNum(g, 0, 5)<<endl;
//
//	int* Q = NULL;
//	Q = Generate(3, 5, 6, Q);
//	PrintValues(Q, 0, 6);
//	delete [] Q;
//
//	stack<int> s;
//	s.push(1);s.push(2);s.push(3);s.push(4);s.push(5);
//	PrintStack(s);
//	cout<<endl;
//	RecursivelyReverseStack(s);
//	PrintStack(s);

//	double r[] = {3, -4, 8, -5, 2, 6, -7};
//	cout<<GetMaxContinuousMul(r, 0, 7)<<endl;
}

void TestStr() {
//	char* a = "312123223445", *b = "21232523311324";
//	cout<<LongestCommonSubString(a, b);

//	char c[] = "ab**cd**e*12";
//	cout<<c<<"\t";
//	cout<<MoveStarToFront(c)<<"\t"<<c<<endl;
//
//	char d[] = "abc123de4fg56";
//	cout<<d<<"\t";
//	RemoveNumbersFromString(d);
//	cout<<d<<endl;
}
